package com.example.toy.core.locker;

import lombok.SneakyThrows;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * ToyLock
 *
 * @author shenbing
 * @date 2021/12/22
 */
public interface ToyLock {

  /**
   * 默认在1分钟内必须上锁
   */
  @SneakyThrows
  default void lockQuickly() {
    lock(1L, TimeUnit.MINUTES);
  }

  void lock(long time, TimeUnit unit) throws InterruptedException, TimeoutException;

  void unlock();

  boolean locked();
}
